package com.fire8.dolphin.service.xmpp;

import org.jivesoftware.smack.packet.Presence;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

/**
 * @author ben
 * 
 *         消息处理器
 * 
 *         Presence.Type.subscribe 加好友 
 *         Presence.Type.unsubscribe 加好友:被拒绝
 *         Presence.Type.subscribed 允许某人的好友添加 
 *         Presence.Type.unsubscribed 拒绝某人的好友添加
 */
public abstract class MessageProcessHandler {

	private Handler handler;
	
	public MessageProcessHandler() {
		init();
	}

	public Handler getHandler() {
		return handler;
	}

	/**
	 * 被加好友收到消息的事件
	 * 
	 * @param presence
	 */
	public abstract void onBeAddFriend(Presence presence);

	/**
	 * 添加人家为好友，被拒绝
	 * 
	 * @param presence
	 */
	public abstract void onAddFriendRefused(Presence presence);

	
	/**
	 * 聊天消息
	 * @param msg
	 */
	public abstract void onChatMsg(org.jivesoftware.smack.packet.Message msg);
	
	private void init() {
		handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case EventTypes.BE_ADD_FRIEND:
					onBeAddFriend((Presence) msg.obj);
					break;
				case EventTypes.ADD_FRIEND_REFUSED:
					onAddFriendRefused((Presence) msg.obj);
					break;
				case EventTypes.CHAT_MSG:
					onChatMsg((org.jivesoftware.smack.packet.Message) msg.obj);
					break;
				}
			}
		};
	}
}
